package com.ht.medicaltreatment.activity

import android.content.res.Configuration
import android.os.Build
import android.text.TextUtils
import android.view.View
import com.blankj.utilcode.util.ActivityUtils
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.TimeUtils
import com.githang.statusbar.StatusBarCompat

import com.gym.baselib.base.BaseActivity
import com.gym.baselib.utils.CacheUtils
import com.ht.medicaltreatment.R
import com.ht.medicaltreatment.activity.haocai2.SubjectListActivity
import com.ht.medicaltreatment.base.CacheKey
import com.ht.medicaltreatment.constant.DevicesSDK
import com.ht.medicaltreatment.utils.PgyUtils
import com.ht.medicaltreatment.utils.ScanUtils
import com.ht.medicaltreatment.utils.WeekDayUtils
import com.ht.medicaltreatment.view.DevicesCheckedDailog
import com.xgst.lib.utils.showToast
import kotlinx.android.synthetic.main.activity_main.img96
import kotlinx.android.synthetic.main.activity_main.imgBack
import kotlinx.android.synthetic.main.activity_main.imgBorrow
import kotlinx.android.synthetic.main.activity_main.imgCheck
import kotlinx.android.synthetic.main.activity_main.imgDebug
import kotlinx.android.synthetic.main.activity_main.imgGroupCheck
import kotlinx.android.synthetic.main.activity_main.imgOut
import kotlinx.android.synthetic.main.activity_main.imgPD
import kotlinx.android.synthetic.main.activity_main.imgPD2
import kotlinx.android.synthetic.main.activity_main.imgSample
import kotlinx.android.synthetic.main.activity_main.imgSampleBox
import kotlinx.android.synthetic.main.activity_main.tvCurrentTime
import kotlinx.android.synthetic.main.activity_main.tvHaoCai
import kotlinx.android.synthetic.main.activity_main.tvName
import kotlinx.android.synthetic.main.activity_main.tvTitle
import java.text.SimpleDateFormat

class MainActivity : BaseActivity(), View.OnClickListener {

    override fun getLayoutId() = R.layout.activity_main

    override fun init() {
        StatusBarCompat.setStatusBarColor(this, getColor(R.color.blue))
        var name = intent.getStringExtra("name")
        if(TextUtils.isEmpty(name)){
            name = CacheUtils.getStringCache(CacheKey.NAME)
        }
        tvName.text = name
        val year = TimeUtils.getNowString(SimpleDateFormat("yyyy"))
        tvCurrentTime.text = year
      /*  calendarView.scrollToCurrent()

        tvTitle.text = "${calendarView.curMonth}月"
        val week = TimeUtils.getCurrentWeek()
        tvCurrentTime.text =
            "${calendarView.curYear}年 ${calendarView.curMonth}月${calendarView.curDay}日 星期$week"
        calendarView.setOnMonthChangeListener { _, month ->
            tvTitle.text = "$month 月"
        }*/
        imgOut.setOnClickListener(this)
        imgCheck.setOnClickListener(this)
        img96.setOnClickListener(this)
        imgGroupCheck.setOnClickListener(this)
        imgPD.setOnClickListener(this)
        imgBack.setOnClickListener(this)
        imgDebug.setOnClickListener(this)
        imgPD2.setOnClickListener(this)
        imgBorrow.setOnClickListener(this)
        imgSample.setOnClickListener(this)
        imgSampleBox.setOnClickListener(this)
        tvHaoCai.setOnClickListener(this)

        PgyUtils.update(this)

        tvTitle.text = "${TimeUtils.getNowString(SimpleDateFormat("MM"))}月"
        WeekDayUtils.getWeekDayList {

        }
        ScanUtils.init()
    }

    override fun onClick(view: View?) {
        //资产盘点 - 仪器设备盘点
        if (view == imgPD && Build.MODEL == "C72" || Build.MODEL == "V9000S") {
            startActivity(AssetInventoryActivity::class.java)
        } else if (view == imgPD && Build.MODEL != "C72") {
            showToast("请使用超高频设备")
        }
        when (view) {
            //临床流程
            imgOut -> startActivity(LinChuangActivity::class.java)
            //转出
            imgGroupCheck -> startActivity(OrderListActivity::class.java)
            //96孔
            img96 -> startActivity(NinetySixeOrderListActivity::class.java)
            //转入
            imgCheck -> {
                startActivity(ShiftToActivity::class.java)
            }
            //退出
            imgBack -> {
                CacheUtils.save(CacheKey.USERNAME, null)
                CacheUtils.save(CacheKey.PASSWORD, null)
                CacheUtils.save(CacheKey.SCAN_UID, null)
                startActivity(LoginActivity::class.java)
                finish()
            }
            //盘点
            imgPD2 -> {
                if (this.getResources().getConfiguration().orientation ==
                    Configuration.ORIENTATION_PORTRAIT) {
                    //竖屏
                    DevicesCheckedDailog(this).show()
                } else {
                    //横屏
                    DevicesSDK.devices = DevicesSDK.ALL_IN_ONE_MACHINE
                    ActivityUtils.startActivity(InventoryOrderListActivity::class.java)
                }
            }

            imgDebug -> {
                LogUtils.i("点击了")
            }
            //借出
            imgBorrow -> startActivity(BorrowListActivity::class.java)
            //样本
            imgSample -> startActivity(SampleActivity::class.java)
            //样本盒
            imgSampleBox -> startActivity(SampleBoxActivity::class.java)
            //实验耗材管理
            tvHaoCai ->  startActivity(SubjectListActivity::class.java)//startActivity(CreateConsumableMoreActivity::class.java)
        }
    }

}